package org.litespring.beans.factory.support;

import org.litespring.beans.factory.config.SingletonBeanRegistry;
import org.litespring.util.Assert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    private final Map<String, Object> singletonBeanMap = new ConcurrentHashMap<>(64);

    @Override
    public void registrySingletonBean(String beanName, Object object) {
        Assert.notNull(beanName,"'beanName' must be null");
        Object oldObject = this.singletonBeanMap.get(beanName);
        if (oldObject != null) {
            throw new IllegalArgumentException("Could not registry ");
        }
        this.singletonBeanMap.put(beanName, object);
    }

    @Override
    public Object getSingletonBean(String beanName) {
        return this.singletonBeanMap.get(beanName);
    }
}
